var utils = (function (exports) {
    let errorHandler

    function foo(fn) {
        callWithErrorHandling(fn)
    }

    function registerErrorHandler(fn) {
        errorHandler = fn
    }

    function callWithErrorHandling(fn) {
        try {
            fn && fn()
        } catch (error) {
            console.log('err')
            errorHandler(error)
        }
    }

    exports.registerErrorHandler = registerErrorHandler
    exports.foo = foo

    return exports
})({})

utils.registerErrorHandler((error) => {
    console.log(error)
})

utils.foo(function () {
    [].length = -1
})
